package com.tiandao.mofang.core.util;

import com.tiandao.mofang.core.RobotSingleton;
import com.tiandao.mofang.ui.MFFrame;

import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.Date;

/**
 * 收集邮件
 */
public class YouJian implements Runnable {
    public static int HAO_NUM = 1;
    public static Robot robot = RobotSingleton.getInstance();

    @Override
    public void run() {
        int i = 1;
        while(i<=HAO_NUM){
            if(i==1){
                MFFrame.textArea.append(new Date()+":    第一个号开始!\n");
                start();
                MFFrame.textArea.append(new Date()+":    第一个号结束!\n");
            }
            if(i==2){
                try {
                    Thread.sleep(3000);
                    robot.keyPress(KeyEvent.VK_ALT);
                    Thread.sleep(200);
                    robot.keyPress(KeyEvent.VK_TAB);
                    robot.keyRelease(KeyEvent.VK_TAB);
                    Thread.sleep(200);
                    robot.keyRelease(KeyEvent.VK_ALT);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                MFFrame.textArea.append(new Date()+":    第二个号开始!\n");
                start();
                MFFrame.textArea.append(new Date()+":    第二个号结束!\n");
            }
            if(i==3){
                try {
                    Thread.sleep(3000);
                    robot.keyPress(KeyEvent.VK_ALT);
                    Thread.sleep(200);
                    robot.keyPress(KeyEvent.VK_TAB);
                    robot.keyRelease(KeyEvent.VK_TAB);
                    Thread.sleep(200);
                    robot.keyPress(KeyEvent.VK_TAB);
                    robot.keyRelease(KeyEvent.VK_TAB);
                    Thread.sleep(200);
                    robot.keyRelease(KeyEvent.VK_ALT);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                MFFrame.textArea.append(new Date()+":    第三个号开始!\n");
                start();
                MFFrame.textArea.append(new Date()+":    第三个号结束!\n");
            }
            if(i==4){
                try {
                    Thread.sleep(3000);
                    robot.keyPress(KeyEvent.VK_ALT);
                    Thread.sleep(200);
                    robot.keyPress(KeyEvent.VK_TAB);
                    robot.keyRelease(KeyEvent.VK_TAB);
                    Thread.sleep(200);
                    robot.keyPress(KeyEvent.VK_TAB);
                    robot.keyRelease(KeyEvent.VK_TAB);
                    Thread.sleep(200);
                    robot.keyPress(KeyEvent.VK_TAB);
                    robot.keyRelease(KeyEvent.VK_TAB);
                    Thread.sleep(200);
                    robot.keyRelease(KeyEvent.VK_ALT);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                MFFrame.textArea.append(new Date()+":    第四个号开始!\n");
                start();
                MFFrame.textArea.append(new Date()+":    第四个号结束!\n");
            }
            if(i==5){
                try {
                    Thread.sleep(3000);
                    robot.keyPress(KeyEvent.VK_ALT);
                    Thread.sleep(200);
                    robot.keyPress(KeyEvent.VK_TAB);
                    robot.keyRelease(KeyEvent.VK_TAB);
                    Thread.sleep(200);
                    robot.keyPress(KeyEvent.VK_TAB);
                    robot.keyRelease(KeyEvent.VK_TAB);
                    Thread.sleep(200);
                    robot.keyPress(KeyEvent.VK_TAB);
                    robot.keyRelease(KeyEvent.VK_TAB);
                    Thread.sleep(200);
                    robot.keyPress(KeyEvent.VK_TAB);
                    robot.keyRelease(KeyEvent.VK_TAB);
                    Thread.sleep(200);
                    robot.keyRelease(KeyEvent.VK_ALT);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                MFFrame.textArea.append(new Date()+":    第五个号开始!\n");
                start();
                MFFrame.textArea.append(new Date()+":    第五个号结束!\n");
            }
            i++;
        }
    }
    //一个窗口
    public static void start(){
        try {
        //去杭州
            Thread.sleep(5000);
            YiDong.yfsxqdt(970,730,YiDong.QDT_HANG_ZHOU_Y);
            Thread.sleep(18000);
            MFFrame.textArea.append(new Date()+":    到达杭州!\n");
            //去邮件坐标
            YiDong.zouLu("2076","1319");
            Thread.sleep(9000);
            //F
            robot.keyPress(KeyEvent.VK_F);
            robot.keyRelease(KeyEvent.VK_F);
            Thread.sleep(4000);
            robot.mouseMove(288,550);
            Thread.sleep(1500);
            robot.mousePress(InputEvent.BUTTON1_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
            Thread.sleep(4000);
            robot.mouseMove(605,736);
            Thread.sleep(1500);
            robot.mousePress(InputEvent.BUTTON1_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
            Thread.sleep(1500);
            robot.mouseMove(770,772);
            Thread.sleep(1500);
            robot.mousePress(InputEvent.BUTTON1_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_MASK);
            //收邮件

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
//        robot.mouseMove(288,550);
//        robot.mouseMove(605,736);
        robot.mouseMove(770,772);
    }
}
